package Month07.day16;

public class duoTai1 {
    public static void main(String[] args) {
//        Animal1 animal1 = new dog1();
//        Animal1 animal2 = new cat1();//将父类指向子类
        An(new dog1());
        An(new cat1());
    }

    public static void An(Animal1 animal) {
        animal.eat();
        if (animal instanceof cat1){
            cat1 cat12 = (cat1) animal;
            cat12.watchFish();
        }else if (animal instanceof dog1){
            dog1 dog1 = (dog1) animal;
            dog1.watchHome();
        }
    }
}

abstract class Animal1 {
    public abstract void eat();
}

class dog1 extends Animal1 {
    @Override
    public void eat() {
        System.out.println("狗吃肉");
    }
    public void watchHome(){
        System.out.println("看家");
    }
}

class cat1 extends Animal1 {
    @Override
    public void eat() {
        System.out.println("猫吃鱼");
    }
    public void watchFish(){
        System.out.println("看着鱼");
    }
}
